//
//  TSCAppDelegate.m
//  Tsc_IOS
//
//  Created by Rio on 15-4-30.
//  Copyright (c) 2015年 idream. All rights reserved.
//

#import "TSCAppDelegate.h"
#import "TSCSDK.h"
#import "TSCVCWelcome.h"

@implementation TSCAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    
    // 初始化APP_DB
    [TSCMyDBHelper initDB];
    
    // 注册ShareSDK
    [self registerShareSDK];
    
    // 初始化第一个界面
    // 方式一：通过代码创建nvc，并设置为AppDelegate的根view
    //    // 创建top vc，并封装到NavigationController中
    //    TSCVCWelcome * vcWelcome = [TSCVCWelcome vcWelcome];
    //    UINavigationController * nvController = [[UINavigationController alloc] initWithRootViewController:vcWelcome];
    //    nvController.navigationBarHidden = true;
    //
    //    // 设置APP的window及root vc
    //    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    //    self.window.rootViewController = nvController;
    //    //    [_window addSubview:nvController.view];
    //    [self.window makeKeyAndVisible];
    
    // 方式二：通过Storyborad设置nvc，自动成为AppDelegate的根view（已通过日志打印证实过）
    // 在Storyboard的编辑界面可以看到nvc的RootViewController就是Welcome。但AppDelegate的根view只能通过代码来测试
    
    return YES;
}

// Mob使用
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url wxDelegate:nil];
}

// Mobo使用
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                 sourceApplication:sourceApplication
                        annotation:annotation
                        wxDelegate:nil];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

#pragma mark 私有方法

// 注册ShareSDK
/* private */ - (void)registerShareSDK {
    // 初始化Mob
    [ShareSDK registerApp:PASSWD_SHARE_SDK_APP_KEY];
    
    // 初始化QQ（空间）
    // 注：1103586261 / aed9b0303e3ed1e27bae87c33761161d，是旧账号
    // 注：别忘了修改Tsc_IOS-Info.plist
    [ShareSDK connectQZoneWithAppKey:PASSWD_QZONE_APP_KEY
                           appSecret:PASSWD_QZONE_APP_SECRET
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    
    // 初始化新浪微博
    [ShareSDK connectSinaWeiboWithAppKey:PASSWD_SINA_WEIBO_APP_KEY
                               appSecret:PASSWD_SINA_WEIBO_APP_SECRET
                             redirectUri:URL_SINA_WEIBO_REDIRECT_URI];
    
    // 初始化Parse
    [Parse setApplicationId:PASSWD_PARSE_APPLICATION_ID
                  clientKey:PASSWD_PARSE_CLIENT_KEY];
}

@end
